<style scoped lang="less">
    .index{
        width: 100%;
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        text-align: center;
        h1{
            height: 150px;
            img{
                height: 100%;
            }
        }
        h2{
            color: #666;
            margin-bottom: 200px;
            p{
                margin: 0 0 50px;
            }
        }
        .ivu-row-flex{
            height: 100%;
        }
    }
</style>
<template>
    <Card style="width:450px;margin:80px auto;">
        <p slot="title">修改密码</p>
        <p>
            <Form ref="formInline" :model="formInline" :rules="ruleInline">
                <FormItem prop="password" label="原始密码" :label-width="120">
                    <Input type="password" size="large" v-model="formInline.oldPwd" placeholder="原始密码">
                        <Icon type="ios-lock-outline" slot="prepend"></Icon>
                    </Input>
                </FormItem>
                <FormItem prop="password" label="新的密码" :label-width="120">
                    <Input type="password" size="large" v-model="formInline.newPwd" placeholder="新的密码">
                        <Icon type="ios-lock-outline" slot="prepend"></Icon>
                    </Input>
                </FormItem>
                <FormItem prop="password" label="再次输入" :label-width="120">
                    <Input type="password" size="large" v-model="formInline.rePwd" placeholder="再次输入">
                        <Icon type="ios-lock-outline" slot="prepend"></Icon>
                    </Input>
                </FormItem>
                <FormItem style="text-align:center;">
                    <Button type="primary"  @click="handleSubmit('formInline')">确认修改</Button>
                </FormItem>
            </Form>
        </p>
        <p>
            <Modal v-model="modal2" width="360"  :closable="false">
                <p slot="header" style="color:#f60;text-align:center">
                    <Icon type="ios-information-circle"></Icon>
                    <span>提示</span>
                </p>
                <div style="text-align:center">
                    <p>密码修改成功！</p>
                    <p>请重新登录</p>
                </div>
                <div slot="footer">
                    <Button type="error" size="large" long :loading="modal_loading" @click="reLogin">确定</Button>
                </div>
            </Modal>
        </p>
    </Card>

</template>
<script>
    import util from '../../libs/util';
    export default {
        data () {
            this.$vnode.fnContext.menuText = '修改密码';
            this.$vnode.fnContext.optionText = '';
            return {
                modal2: false,
                modal_loading: false,
                formInline: {
                    oldPwd: '',
                    newPwd: '',
                    rePwd: '',
                    labelWidth:120
                },
                ruleInline: {
                    oldPwd: [
                        { required: true, message: '请输入您原来的登陆密码.', trigger: 'blur' },
                        { type: 'string', min: 6, message: '登陆密码最少6位', trigger: 'blur' }
                    ],
                    newPwd: [
                        { required: true, message: '请输入您新的登陆密码.', trigger: 'blur' },
                        { type: 'string', min: 6, message: '登陆密码最少6位', trigger: 'blur' }
                    ],
                    rePwd: [
                        { required: true, message: '请重复您新的登陆密码.', trigger: 'blur' },
                        { type: 'string', min: 6, message: '登陆密码最少6位', trigger: 'blur' }
                    ]
                }
            }
        },
        methods: {
            handleSubmit(name) {
                this.$refs[name].validate(function(valid){
                    if (valid) {
                        util.postJsonData('/admin/admin/changePwd',
                            {loginId:util.loginId,oldPwd:this.formInline.oldPwd,newPwd:this.formInline.newPwd,rePwd:this.formInline.rePwd},
                            this,
                            (data)=>{
                                console.log(data);
                                console.log('密码修改成功！');
                                // this.$Modal.info({
                                //     title:'提示',
                                //     content:'修改密码成功',
                                //     onOk:()=>{
                                //         this.$router.push('/');
                                //     }
                                // });
                                this.modal2 = true;
                                // this.modal_loading = true;
                                setTimeout(() => {
                                    this.modal_loading = false;
                                    this.modal2 = false;
                                    this.$Message.success('请重新登录~');
                                    this.$router.push('/');
                                }, 2000);
                                // this.$router.push('/');

                            });
                    } else {
                        this.$Message.error('验证失败!');
                    }
                }.bind(this));
            },
            reLogin() {
                // 不可点击
                this.modal_loading = true;
                this.$router.push('/');
            }
        }
    }
</script>
